<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
session_start();

class pass extends CI_Controller {

    public function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in_user')) {
            $this->logged_in = TRUE;
        } else {
            redirect('login/', 'refresh');
        }
        $this->load->model('Dao');
        $this->load->helper('date');
    }

    public function index() {
        $user = $this->session->userdata('logged_in_user');
        $user = $this->Dao->findUserById($user->id);

        $data['title'] = 'Welcome to wfaces';
        $data['description'] = 'NONE';
        $data['keywords'] = 'Key, words, of, the, page';
        $data['view'] = 'v_pass';
        $data['user'] = $user;
        $this->load->view('templates/template', $data);
    }

    public function change() {
        $current = $this->input->post("current");
        $user_id = $this->session->userdata('logged_in_user')->id;

        if (!$this->Dao->verifPass($user_id, $current)) {
            die("0");
        }
        $data['password'] = $this->input->post("new");
        $this->Dao->updateUserProfileAll($user_id, $data);
        echo "1";
    }

}

?>
